package dreamCookGame.chickenMiniGame;

import dreamCookGame.Item;
import dreamCookGame.References;
import dreamCookGame.Scene;

public class ChickenMiniGame extends Scene {
	final int BEAR_ENTITY_INDEX = 0;
	public Entity[] _entities;
	public boolean[] _caughtTracker;
	public boolean _gameDone;
	int countDown;
	
	public ChickenMiniGame() {
		super("chickenMiniGame", "chickenMiniGameBackground", null, 0, 0, null, null, null);
		
		_gameDone = false;
		countDown = 50;
		
		_caughtTracker = new boolean[3];
		_caughtTracker[0] = false;
		_caughtTracker[1] = false;
		_caughtTracker[2] = false;

		String[] bearImages = {"chickenMiniGameBear"};
		Entity bear = new BearEntity(bearImages[0], bearImages, 400,300);
		
		String[] chicken1Images = {"chickenMiniGameBrownChicken"};
		Coop coop1 = new Coop(43,34,97,62);
		Entity redChicken = new ChickenEntity(chicken1Images[0], chicken1Images, 200, 300, bear, coop1);
		
		String[] chicken2Images = {"chickenMiniGameBrownChicken"};
		Coop coop2 = new Coop(334,34,97,62);
		Entity brownChicken = new ChickenEntity(chicken2Images[0], chicken2Images, 400, 400, bear, coop2);
		
		String[] chicken3Images = {"chickenMiniGameBrownChicken"};
		Coop coop3 = new Coop(655,34,97,62);
		Entity whiteChicken = new ChickenEntity(chicken3Images[0], chicken3Images, 400, 200, bear, coop3);
		
		_entities = new Entity[4];
		_entities[0] = bear;
		_entities[1] = redChicken;
		_entities[2] = brownChicken;
		_entities[3] = whiteChicken;
		//super._itemsBack = _entities;	
	}
	
	public void loadResources(References reference) {
		super.loadResources(reference);
		for(int i=0; i<_entities.length;i++){
			_entities[i].loadResources(reference);
		}
	}
	
	public void update(){
		for(int i=0; i<_entities.length;i++) {
			Entity tempEntity = _entities[i];
			tempEntity.update();
			if(i!=BEAR_ENTITY_INDEX){
				if(((ChickenEntity)tempEntity)._myCoop.checkInside((int)tempEntity._location.getX(), (int)tempEntity._location.getY())){
					((ChickenEntity)tempEntity).setCaught();
					_caughtTracker[i-1]=true;
					//System.out.println(""+_caughtTracker[0]+_caughtTracker[1]+_caughtTracker[2]);
				}
			}
		}
		
		if(_caughtTracker[2]&&_caughtTracker[1]&&_caughtTracker[0]){
			if(countDown<=0){
				_gameDone = true;
			}
			countDown--;
		}
	}

	public void moveCharacter(char direction) {
		((BearEntity)_entities[BEAR_ENTITY_INDEX]).setInMotion(direction);
	}

	public void stopCharacter(char direction) {
		((BearEntity)_entities[BEAR_ENTITY_INDEX]).stopMotion(direction);
	}

	public void setCharacterLocation(int x, int y) {
		((BearEntity)_entities[BEAR_ENTITY_INDEX]).setLocation(x, y);
	}
}